-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - bevy_pbr: Normalize skinned normals #6543
[Merged by Bors] - bevy_pbr: Normalize skinned normals #6543
Conversation
This was forgotten in bevyengine#5666 when normalization of normals was moved from the fragment to vertex stage.
This should be the correct fix. But I want it to see some testing. As noted in the comment from the code, normalization is not meant to be applied to all normals in the fragment shader before normal mapping. It may be that we should make sure to normalise all normals at the end of the apply_normal_mapping() function though and that may be more difficult to find errors with so maybe I'll add that... |
So the remaining bit that I'm unsure of is whether perspective correct interpolation causes normals to be significantly scaled such that they are no longer unit normals. The safe bet then would be: diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl
index 58eb7023e..3e9046353 100644
--- a/crates/bevy_pbr/src/render/pbr_functions.wgsl
+++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl
@@ -91,12 +91,12 @@ fn apply_normal_mapping(
// calculates the normal maps so there is no error introduced. Do not change this code
// unless you really know what you are doing.
// http://www.mikktspace.com/
- N = normalize(Nt.x * T + Nt.y * B + Nt.z * N);
+ N = Nt.x * T + Nt.y * B + Nt.z * N;
#endif
#endif
#endif
- return N;
+ return normalize(N);
}
// NOTE: Correctly calculates the view vector depending on whether |
The interpolated world normals were not being re-normalized for the non-normal mapping case.
This fixes it for me. |
bors r+ |
# Objective - Make the many foxes not unnecessarily bright. Broken since #5666. - Fixes #6528 ## Solution - In #5666 normalisation of normals was moved from the fragment stage to the vertex stage. However, it was not added to the vertex stage for skinned normals. The many foxes are skinned and their skinned normals were not unit normals. which made them brighter. Normalising the skinned normals fixes this. --- ## Changelog - Fixed: Non-unit length skinned normals are now normalized.
# Objective - Make the many foxes not unnecessarily bright. Broken since bevyengine#5666. - Fixes bevyengine#6528 ## Solution - In bevyengine#5666 normalisation of normals was moved from the fragment stage to the vertex stage. However, it was not added to the vertex stage for skinned normals. The many foxes are skinned and their skinned normals were not unit normals. which made them brighter. Normalising the skinned normals fixes this. --- ## Changelog - Fixed: Non-unit length skinned normals are now normalized.
Objective
Solution
Changelog